package com.csii.adhoc.controller.board;

import com.csii.adhoc.annotation.OperationLog;
import com.csii.adhoc.board.filter.FilterUnitVo;
import com.csii.adhoc.board.service.FilterUnitService;
import com.csii.adhoc.util.DateUtils;
import com.csii.result.APIResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @description: 过滤组件控制层
 * @author: panChuanJiang
 * @create: 2021-02-05 09:25
 */
@Slf4j
@RestController
@RequestMapping("filter")
public class FilterUnitController {
    @Resource
    private FilterUnitService filterUnitService;

    @RequestMapping("saveFilterUnitInfo")
    @OperationLog("过滤组件信息维护")
    public APIResult saveFilterUnitInfo(@RequestBody FilterUnitVo filterUnitVo){
        String userId = Optional.ofNullable(String.valueOf(SecurityUtils.getSubject().getPrincipal())).orElse("未知用户");
        filterUnitVo.setUpdatedBy(userId).setUpdatedDt(DateUtils.getDateString("yyyyMMddHHmmss"));
        filterUnitService.FilterUnitMaintain(filterUnitVo,filterUnitVo.getOptMode());
        return APIResult.successResult(null);
    }

    @RequestMapping("queryFilterUnitInfo")
    public APIResult queryFilterUnitInfo(@RequestBody FilterUnitVo filterUnitVo){
        return APIResult.successResult(filterUnitService.selectOneFilterUnit(filterUnitVo.getUnitId()));
    }

}
